﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

public partial class MoiQuanHe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.BindList();
        }
    }
    private void BindList()
    {
        int investor_id = 0;
        if (!string.IsNullOrEmpty(Session["MaChuDauTu"].ToString()))
        {
            investor_id = int.Parse(Session["MaChuDauTu"].ToString());
        }
        
        wdgMoiQH.DataSource = new BLL.BORepresentative(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()).GetThongTinMQH(investor_id);
        wdgMoiQH.DataBind();
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        BLL.BORepresentative boReprt = new BLL.BORepresentative(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());

        if (!string.IsNullOrEmpty(Session["MaChuDauTu"].ToString()))
        {
            boReprt.Ma_chu_DT = int.Parse(Session["MaChuDauTu"].ToString());
            boReprt.Ho_MQH = txtHo.Text;
            boReprt.Ten_MQH = txtName.Text;
            boReprt.Tinh_cach = txtTinhCach.Text;
            boReprt.Vi_tri = txtChucDanh.Text;
            boReprt.Dia_chi = txtDiaChi.Text;
            boReprt.Dien_thoai = txtDienThoai.Text;
            boReprt.CreateMQH();

            this.BindList();
        }

    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Session["MaChuDauTu"].ToString()))
        {
            BLL.BORepresentative boReprt = new BLL.BORepresentative(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
            boReprt.Ho_MQH = txtHo.Text;
            boReprt.Ten_MQH = txtName.Text;
            boReprt.Tinh_cach = txtTinhCach.Text;
            boReprt.Vi_tri = txtChucDanh.Text;
            boReprt.Dia_chi = txtDiaChi.Text;
            boReprt.Dien_thoai = txtDienThoai.Text;
            boReprt.UpdateMQH();

            this.BindList();
        }
    }
    protected void btnSelect_Click(object sender, EventArgs e)
    {
        ClientScript.RegisterStartupScript(typeof(Page), "closePage", "window.open('Close.htm', '_self', null);", true);
    }
}